/**
 * 购物车页面路由地址
 *
 */
// 导入axios实例
import http from "@/utils/http";
//登录类型
export interface liginType {
  [x: string]: any;
  nickName: string;
  name: string;
  userId: number;
  token: string;
}
export interface cartInfoListType {
  cartPrice: number,
  couponInfoList: null,
  createTime: string,
  id: number,
  imgUrl: string,
  isChecked: number,
  isOrdered: number,
  operateTime: string,
  orderTime: null,
  skuId: number,
  skuName: string,
  skuNum: number,
  skuPrice: number,
  sourceId: number,
  sourceType: string,
  userId: string,
}
//商品数据类型
export interface reqCartListType {
  [x: string]: {
    cartPrice:
    // 导入axios实例
    number; couponInfoList: null; createTime: string; //登录类型
    //登录类型
    id: number; imgUrl: string; isChecked: number; isOrdered: number; operateTime: string; orderTime: null; skuId: number; skuName: string; skuNum: number; skuPrice: number; sourceId: number; sourceType: string; userId: string;
  }[];
  data: [],
  

}

/**
 * @desc 登录
 * @param {*} params {phone: 手机号；password：密码}
 * @returns
 */
export const reqLogin = (phone: string, password: string) => {
  return http.post<any, liginType>("/api/user/passport/login", {
    phone,
    password,
  });
};

/** @desc 添加到购物车
 * @returns  Promise
 */
export const reqCartList = () => {
  return http.get<any, reqCartListType[]>("/api/cart/cartList");
};

/** @desc 切换商品选中状态
 * @returns  Promise
 */
export const reqChangeCart = (id: string | number, isChecked:string |number) => {
  return http.get(`/api/cart/checkCart/${id}/${isChecked}`);
};

/** @desc 商品全选 post
 * @returns  Promise
 */

export const reqAllChecked = (skuIdList: any, isChecked: number) => {
  return http.post(`/api/cart/batchCheckCart/${isChecked}`, skuIdList);
};

/** @desc 删除单个商品 delete
 * @returns  Promise
 */
export const reqDeleteOne = (Id: number) => {
  return http.delete(`/api/cart/deleteCart/${Id}`);
};

/** @desc 删除全选商品 delete
 * @returns  Promise
 */
export const reqAllDelete = (List: any) => {
  return http.post("/api/cart/batchDeleteCart", List);
};
